﻿using AMDev.BNET.ClientAPI;
using AMDev.BNET.ClientAPI.WoW;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ClientAPI.Test.ConsoleApplication
{
    class Program
    {
        static void Main(string[] args)
        {
            WoWAPIClient client = null;
            BNETResponse<WoWRealm[]> realmsResponse = null;
            BNETResponse<WoWCharacter> characterResponse = null;
            Task<BNETResponse<WoWRealm[]>> realmsTask = null;
            Task<BNETResponse<WoWCharacter>> characterTask = null;
            WoWRealm[] realmsArray = null;
            WoWRealmsCollection realms = null;
            WoWCharacter character = null;

            Console.WriteLine("Fetching character Saberwulf from Doomhammer and realms statuses.");
            client = new WoWAPIClient(BNETRegionsEnumeration.EU);
            realmsTask = client.GetRealmsStatusesAsync();
            characterTask = client.GetCharacterProfileAsync("Doomhammer", "Saberwulf", WoWCharacterProfileCaps.Stats);
            realmsTask.Wait();
            realmsResponse = realmsTask.Result;
            if (realmsResponse.HasError)
            {
                Console.WriteLine("An error occured fetching realm list: ");
                Console.WriteLine(realmsResponse.ErrorValue.ToString());
                Console.WriteLine(realmsResponse.ErrorMessage);
            }
            else
            {
                realmsArray = realmsResponse.ResponseData;
                realms = new WoWRealmsCollection(realmsArray);
                Console.WriteLine(realms.ToString());
            }
            characterTask.Wait();
            characterResponse = characterTask.Result;
            if (realmsResponse.HasError)
            {
                Console.WriteLine("An error occured fetching character details: ");
                Console.WriteLine();
                Console.WriteLine(realmsResponse.ErrorValue.ToString());
                Console.WriteLine();
                Console.WriteLine(realmsResponse.ErrorMessage);
            }
            else
            {
                character = characterResponse.ResponseData;
                Console.WriteLine(character.ToString());
            }
            Console.WriteLine("Press key to continue...");
            Console.ReadKey();
        }
    }
}

